<template>
	<view class="good-list">
		<view class="good-ul">
			<view class="good-li" @click="go2Detail(item.id)" v-for="item in list" :key="item.id">
				<image class="good-img" mode="widthFix" :src="item.goodImg"></image>
				<view class="item">
					<view class="titel">{{item.goodName}}</view>
					<view class="item-text">
						<view class="price">{{item.goodPrice}} 元</view>
						<view class="sold">已售{{item.goodSold}}件</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "good-list",
		// 设置子组件接受父组件的选项
		props: {
			list: {
				type: Array,
				default () {
					return []
				}
			}
		},
		methods: {
			go2Detail(id) {
				uni.navigateTo({
					url: "/pages/detail/detail?id=" + id
				})
			}
		}
	}
</script>

<style lang="scss">
	/* list和sass选择器可以父子嵌套 */
	.good-list {
		background-color: #fff;
		.good-ul {
			width: 98%;
			margin: 0 auto;
			column-count: 2;
			column-gap: 18rpx;
			.good-li {
				// width: 40%;
				// margin: 8px;
				margin-bottom: 10px;
				padding: 20upx;
				border: 1px solid #eee;
				border-radius: 6px;
				box-shadow: 0px 0px 4px #eee;
				.good-img {
					width: 200upx;
					height: 220upx;
					display: flex;
					margin: 0 auto;
				}
				.item {
					flex: 1;
					.titel {
						font-size: 14px;
						line-height: 20px;
						height: 40px;
						margin-top: 20px;
						margin-bottom: 15px;
						overflow: hidden;
					}
					.item-text {
						display: flex;
						align-items: center;
						padding-bottom: 8px;
						.price {
							font-size: 16px;
							color: red;
						}
						.sold {
							font-size: 12px;
							color: gray;
							margin-left: 15px;
						}
					}
				}
			}
		}
	}
</style>